package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}15:58
 */
public class interview54 {
    public int missingNumber(int[] nums) {
        int left = 0;
        int right = nums.length-1;
        while (left <= right){
            int mid = (left+right) >>> 1;
            if (nums[mid] != mid){
                if (mid == 0||nums[mid - 1] == mid - 1){
                    return mid;
                }
                right = mid - 1;
            }
            if (nums[mid] == mid){
                left = mid + 1;
            }
        }
        if (left == nums.length){
            return left;
        }
        return  -1;
    }
}
